package org.hhchat.leetcode.tree;

import org.hhchat.leetcode.dataStruct.TreeNode;

/**
 * Created this one by HMH on 2017/10/2.
 */
public class code563_easy {
    static class Solution {

        public int findTilt(TreeNode root) {
            visit(root);
            return sum;
        }


        public int visit(TreeNode treeNode) {
            if (treeNode == null) {
                return 0;
            }
            int left = 0;
            int right = 0;
            left = visit(treeNode.left);
            right = visit(treeNode.right);

            sum += Math.abs(left - right);

            return left + right + treeNode.val;
        }

        int sum = 0;
    }
}
